import React, { Component } from 'react';
import { index_banner, user_login } from '../../utils/api'
import './Banner.scss'
import { Swiper, Toast } from 'antd-mobile'

class Banner extends Component {
    // 挂载期(挂载期的方法会自动执行，而且只执行一次)
    constructor(props) {//这个函数会在组件挂载前就执行，组件并没有显示在页面上
        super(props);
        // console.log('constructor');
        this.state = {
            list: [],
        }//初始化组件状态
    }
    componentDidMount() {
        index_banner().then((res) => {
            this.setState(
                this.state.list = res.data.list
            )
        })
    }
    render() {
        return (
            <div className='banner'>
                <Swiper className='myswiper' loop autoplay >
                    {
                        this.state.list.map((item, index) => {
                            return <Swiper.Item key={index}><img src={item.pic} alt="" /> </Swiper.Item>
                        }
                        )
                    }
                </Swiper>
            </div>
        );
    }

}

export default Banner;